<?php

namespace App\Models;


class SiteConfig extends Base
{

    // 系统配置
    protected $table = 'site_config';

    // 缓存字段，用于搜索绑定的字段
    protected $cacheFields = ['id', 'field'];

    // 获取配置信息
    public function getConfig()
    {
        // 获取缓存
        $bang     = $this->bang;
        $is_cache = $this->is_cache || $bang;
        $args     = [];
        //$args      = compact('where');
        if($is_cache){
            $cacheName = $this->cacheKey('lists', $args);
            $cacheData = $this->cacheClass()->getCache($cacheName);
            if(!empty($cacheData)){
                /*// 检查是否已经绑定
                if(($cacheData) && (!empty($cacheData['list']))){
                    $this->checkBangList($cacheData['list'], $cacheName);
                }*/

                return $cacheData;
            }
        }

        $lists  = $this->get()->toArray();
        $config = array_column($lists, 'value', 'field');
        // 保存为缓存
        if($is_cache){
            $this->addCacheList($lists, $cacheName, $config, 'list');
        }

        return $config;
    }


    // 定义验证操作
    public function rules()
    {

        $add = [
        ];

        $edit = [
        ];

        $info = [
        ];


        $rule = [
            'field' => 'required',
            'value' => 'required',
        ];


        $msg = [
            'id'       => '自编号',
            'field'    => '字段',
            'name'     => '中文名',
            'value'    => '中文值',
            'describe' => '描述',
            'ctime'    => '时间',
            'mtime'    => '时间',
        ];

        return ['rule' => $rule, 'msg' => $msg, 'add' => $add];
    }
}
